﻿using System;
using System.Collections.Generic;
using System.Text;
using Nissen_Dao;
using Nissen_Model;
using PosHacker;

namespace Nissen_Manage.Forms
{
	public class PasswordChangeService
	{
		public void ChangePassword(string pwd)
		{
			NissenSSODao nissenSsoDao = new NissenSSODao();
			nissenSsoDao.UpdateNissenSSOPwd(pwd);
		}



        public IList<string> ChangePasswordOnebyOne(string pwd)
        {
            try
            {

            }
            catch (Exception)
            {
                
                throw;
            }
            IList<string> reslist = new List<string>();

            NissenSSODao nissenSsoDao = new NissenSSODao();
            IList<NissenSSO> _listNissenSSO =
                nissenSsoDao.GetNissenSSO();


            foreach (var nissenSso in _listNissenSSO)
            {

                try
                {
                    POSHacker _posHacker = POSHacker.GetInstance(nissenSso.NissenSSOCode, nissenSso.NissenSSOPWD);

                    _posHacker.Login();
                    if (_posHacker.ChangPassword(nissenSso.NissenSSOPWD, pwd))
                    {
                        nissenSso.NissenSSOPWD = pwd;
                        nissenSsoDao.SaveOrUpdate(nissenSso);
                    }
                    else
                    {
                        reslist.Add(nissenSso.NissenSSOCode);
                    }
                }
                catch (Exception ex)
                {
                    reslist.Add(nissenSso.NissenSSOCode + ":" + ex.Message);
                }
            }

            return reslist;
        }
	}
}
